
import { Button, } from 'antd';
import { observer} from "mobx-react";
import {toJS} from 'mobx';
import {WeaDialog,WeaFormItem,WeaSearchGroup,WeaNewScroll,WeaRightMenu} from 'ecCom';
import {WeaSwitch} from 'comsMobx';
import WeaCptTableEdit from '../CapitalTableEdit/WeaCptTableEdit'
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

@observer
class InstockCheckInfoDialog extends React.Component {
  constructor(props) {
    super(props);
    this.state={
    }
  }
  componentDidMount(){
  }
  componentWillReceiveProps(nextProps) {
 
  }
  render() {
    const {showInstockCheckInfo,subInfoData,subInstockInfo,showDetail,saveSubInfoData} = this.props.contentStore;
    return (
        <div>
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@fpvo1h`} 
                style={{ width: 900, height: 550 }} 
                icon='icon-coms-fa' 
                iconBgcolor='#f14a2d' 
                title={getLabel(6050,"资产验收入库")} 
                visible={showDetail}
                buttons={this.getBottomButtons()}
                onCancel={()=>{showInstockCheckInfo(false)}}
            >
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@vr3k2x`} datas={this.getRightMenu()} onClick={this.onRightMenuClick.bind(this)}  >
                    <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@v5cssr`}  height={"100%"}>
                        {this.getFormFields()}
                        <WeaCptTableEdit ecId={`${this && this.props && this.props.ecId || ''}_WeaCptTableEdit@zjssin`}
                            ref={ref => {this.props.contentStore.instockRemind = ref}}
                            title={getLabel(83579,"入库明细")}
                            showGroup={true}
                            needAdd={false}
                            needCopy={true}
                            columns={toJS(subInstockInfo.columnData || {})}
                            datas={toJS(subInfoData || [])}
                            datas_0={toJS(subInstockInfo.columnDefine || [])}
                            onChange={saveSubInfoData}
                        />
                    </WeaNewScroll>
                </WeaRightMenu>
            </WeaDialog>
            
        </div>)
    }
    getRightMenu(){
        const {rightMenu,visible } = this.props.contentStore;
        let btnArr = [];
        rightMenu && rightMenu.length>0 && rightMenu.map(m=>{
            btnArr.push({
                icon: <i className={m.menuIcon} />,
                content: m.menuName,
                disabled:visible,
            })
        });
    	return btnArr
    }
    onRightMenuClick(key){
        const {rightMenu,doCheckInstock } = this.props.contentStore;
        let that = this;
        rightMenu &&  rightMenu.length>0  && rightMenu.map((m,i)=>{
        	if(Number(key) == i){
                if(m.type == "BTN_CHECK"){ //验收
                    doCheckInstock();
                }
            }
        });
    }

    getBottomButtons=()=>{
        const {rightMenu,showInstockCheckInfo,doCheckInstock,visible } = this.props.contentStore;
        let btnArr = [];
        rightMenu && rightMenu.length>0  && rightMenu.map(m=>{
            m.isTop == '1' && btnArr.length < 4 && btnArr.push(
                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@7f3wtl@${m.type}`} type="primary"  disabled={visible}
                    onClick={()=>{
                        if(m.type == "BTN_CHECK"){ //验收
                            doCheckInstock();
                        }
                    }}>
                    {m.menuName}
                </Button>
            );
        });
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@v51d4s@close`}  type="primary" disabled={visible} onClick={()=>{showInstockCheckInfo(false)}}>{getLabel(309,'关闭')}</Button>)  
        return btnArr;
    }
    getFormFields(){
        const {mainInstockInfo,mainForm} = this.props.contentStore;
        const {isFormInit} = mainForm;
        let group = [];
        isFormInit &&  mainInstockInfo.map((c,i) =>{
          let items = [];
          c.items.map(fields => {
            let hide = false;
            let hasunderline = false;
            //只读样式控制
            if(fields.viewAttr == "1" || (fields.conditionType == "BROWSER" && fields.browserConditionParam.viewAttr == "1")) {
                hasunderline = true
            }
            if(hasunderline){
                items.push({
                    com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@j204iy@${fields.domkey[0]}`}
                        label={`${fields.label}`}
                        labelCol={{span: `${fields.labelcol}`}}
                        wrapperCol={{span: `${fields.fieldcol}`}} underline>
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@qrmvd3@${fields.domkey[0]}`} fieldConfig={fields} form={mainForm} />
                        </WeaFormItem>),
                    colSpan:1,
                    hide:hide
                });
            }else{
                items.push({
                    com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@dpl9ac@${fields.domkey[0]}`}
                        error={mainForm.getError(fields)}
                        tipPosition="bottom"
                        label={`${fields.label}`}
                        labelCol={{span: `${fields.labelcol}`}}
                        wrapperCol={{span: `${fields.fieldcol}`}} >
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@2zgpvl@${fields.domkey[0]}`} fieldConfig={fields} form={mainForm} />
                        </WeaFormItem>),
                    colSpan:1,
                    hide:hide
                });
            }
            
          });
          group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@5dd8j2@${i}`} needTigger={true} title={c.title} col={2} showGroup={c.defaultshow} items={items}/>)
        });
        return group;
    }

}

export default InstockCheckInfoDialog;